/**
 * @FileName ConcreteIterator.java
 * @Package com.designMode.iterator
 * -------------------------------------
 * @function Please write description of function
 * @Date 2016-1-6 下午4:35:58
 * -------------------------------------
 * Copyright (c) 2016,顾博君 All Rights Reserved.
 */
package com.designMode.iterator;

import java.util.Vector;

/**
 * @author 顾博君
 * @ClassName ConcreteIterator
 * @Date 2016-1-6 下午4:35:58
 * @Function 具体迭代器
 */
public class ConcreteIterator implements Iterator {
    private Vector<Object> vector;
    private int cursor = 0;

    public ConcreteIterator(Vector<Object> _vector) {
        vector = _vector;
    }

    /**
     * 获取下一个元素，没有则返回空
     *
     * @return 下一个元素
     */
    @Override
    public Object next() {
        Object result = null;
        if (hasNext()) {
            result = vector.get(cursor++);
        }
        return result;
    }

    @Override
    public boolean hasNext() {
        return cursor != vector.size();
    }

    @Override
    public boolean remove() {
        vector.remove(cursor);
        return true;
    }
}
